<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/26
 * Time: 22:25
 */
if(!isset($_POST['name'])){
    die('name is not define');
}
if(!isset($_POST['age'])){
    die('age is not define');
}
$name=$_POST['name'];
$age=$_POST['age'];

if(empty($name)){
    die('name is empty');
}
if(empty($age)){
    die('age is empty');
}
$pdo=new PDO("mysql:dbname=text09251;host=127.0.0.1","root");
$pdo->exec("SET NAMES 'utf8';");
$sql = "INSERT INTO tb_user(name,age) VALUES ('$name',$age)";
$res = $pdo->query($sql);
//查找
$sql1 = "SELECT * FROM tb_user;";
$res1 = $pdo->query($sql1);

echo "<table border='1' >";
echo "<tr>
<th>名字</th>
<th>年龄</th>
</tr>";
foreach ($res1 as $tb_user) {
    echo "<tr>";
    echo "<td>{$tb_user['name']}</td>";
    echo "<td>{$tb_user['age']}</td>";
    echo "</tr>";
}
